package com.longxi.tianjintianbao.ui.adapter.multitype;

import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import com.longxi.tianjintianbao.AppConst;
import com.longxi.tianjintianbao.R;
import com.longxi.tianjintianbao.model.RepairType;
import com.longxi.tianjintianbao.ui.activity.repair_publish.RepairActivity;
import com.longxi.tianjintianbao.ui.activity.repair_publish.RepairContentActivity;

import me.drakeet.multitype.ItemViewBinder;

/**
 * Created by cxw on 2018/2/20.
 */
public class RepairTypeViewBinder extends ItemViewBinder<RepairType.Type, RepairTypeViewBinder.ViewHolder> {

    OnClickListener listener;
    public RepairTypeViewBinder setListener(OnClickListener listener){
        this.listener = listener;
        return this;
    }

    @NonNull
    @Override
    protected ViewHolder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        View root = inflater.inflate(R.layout.item_repair_type, parent, false);
        return new ViewHolder(root);
    }

    @Override
    protected void onBindViewHolder(@NonNull ViewHolder holder, @NonNull RepairType.Type repairType) {
        holder.mBtnType.setText(repairType.repaircategory);
        if("".equals(repairType.repaircategory) || repairType.repaircategory == null){
            holder.mBtnType.setVisibility(View.GONE);
        }else{
            holder.mBtnType.setVisibility(View.VISIBLE);
        }
        holder.mBtnType.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(listener != null){
                    listener.onClick(holder.getAdapterPosition());
                }
            }
        });
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        Button mBtnType;
        ViewHolder(View itemView) {
            super(itemView);
            mBtnType = itemView.findViewById(R.id.btnType);
        }
    }

    public interface OnClickListener {
        void onClick(int position);
    }
}
